#ifndef	GNTHELPER_H
#define GNTHELPER_H

template <class U>
struct GnTHelper
{
	template<typename listType, typename vectorType, typename findtype>
	static	bool FindVector(listType& vectorVar,
		findtype& findData, vectorType& out)
	{
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		while ( iT != vectorVar.end() )
		{
			if( (*iT) == findData )
			{
				out = (vectorType)(*iT);
				return true;
			}
			++iT;
		}
		return false;
	};

	template<typename listType, typename vectorType>
	static	bool GetMin(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( (*iT) < out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};
	template<typename listType, typename vectorType>
	static	bool GetMax(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( (*iT) > out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};

};

template <class U>
struct GnTHelper<U*>
{
	template<typename listType, typename vectorType, typename findtype>
	static	bool FindVector(listType& vectorVar,
		findtype& findData, vectorType& out)
	{
		listType::iterator iT = vectorVar.begin();
		while ( iT != vectorVar.end() )
		{
			if( *(*iT) == findData )
			{
				out = (vectorType)(*iT);
				return true;
			}
			++iT;
		}
		return false;
	};
	template<typename listType, typename vectorType>
	static	bool GetMin(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( *(*iT) < out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};
	template<typename listType, typename vectorType>
	static	bool GetMax(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( *(*iT) > out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};
};

template <class U>
struct GnTHelper<U*&>
{
	template<typename listType, typename vectorType, typename findtype>
	static	bool FindVector(listType& vectorVar,
		findtype& findData, vectorType& out)
	{
		listType::iterator iT = vectorVar.begin();
		while ( iT != vectorVar.end() )
		{
			if( *(*iT) == findData )
			{
				out = (vectorType)(*iT);
				return true;
			}
			++iT;
		}
		return false;
	};

	template<typename listType, typename vectorType>
	static	bool GetMin(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( *(*iT) < out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};

	template<typename listType, typename vectorType>
	static	bool GetMax(listType& vectorVar, vectorType& out)
	{
		vectorType minData;
		GnVector<vectorType>::iterator iT = vectorVar.begin();
		if( iT != vectorVar.end() )
			out = (vectorType)(*iT);
		else
			return false;

		while ( iT != vectorVar.end() )
		{
			if( *(*iT) > out )
			{
				out = (vectorType)(*iT);
			}
			++iT;
		}
		return true;
	};
};

struct THelper
{
	template<typename tKey, typename tValue>
	GNFORCEINLINE static bool Add( std::map<tKey, tValue>& _stl, tKey& _key, tValue& _value )
	{
		std::map<tKey, tValue>::_Pairib ret = _stl.insert( std::pair<tKey, tValue>(_key, _value ) );
		return ret.second;
	}
	template<typename tKey, typename tValue>
	GNFORCEINLINE static void Remove( std::map<tKey, tValue>& _stl, tKey& _key )
	{
		_stl.erase( _key );
	}
};

#endif // GNTHELPER_H